package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.example.EmpInfoExample.E_NAME_OR_PHONE;
import static org.jsola.hr.example.EmpInfoExample.N_NAME_OR_PHONE;
import static org.jsola.hr.example.SalaryBillExample.*;

/**
 * 工资条
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SalaryBillQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_TABLE_ID, example = E_TABLE_ID)
    @Length(max = 32)
    private String tableId;

    @ApiParam(value = N_EMP_IN_COMPANY, example = E_EMP_IN_COMPANY)
    private Boolean empInCompany;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_YEAR, example = E_YEAR)
    @Length(max = 32)
    private String year;

    @ApiParam(value = N_MONTH, example = E_MONTH)
    @Length(max = 32)
    private String month;

    @ApiParam(value = N_SALARY_AMOUNT, example = E_SALARY_AMOUNT)
    private BigDecimal salaryAmount;

    @ApiParam(value = N_SALARY_REAL, example = E_SALARY_REAL)
    private BigDecimal salaryReal;

    @ApiParam(value = N_SEND_TYPE, example = E_SEND_TYPE)
    private Integer sendType;

    @ApiParam(value = N_SEND_STATUS, example = E_SEND_STATUS)
    private Boolean sendStatus;

    @ApiParam(value = N_READ_STATUS, example = E_READ_STATUS)
    private Boolean readStatus;

    @ApiParam(value = N_CHECK_STATUS, example = E_CHECK_STATUS)
    private Boolean checkStatus;

    @ApiParam(value = N_WITHDRAWN_STATUS, example = E_WITHDRAWN_STATUS)
    private Boolean withdrawnStatus;

    @ApiParam(value = N_SEND_TIME, example = E_SEND_TIME)
    private Date sendTime;

    @ApiParam(value = N_READ_TIME, example = E_READ_TIME)
    private Date readTime;

    @ApiParam(value = N_CHECK_TIME, example = E_CHECK_TIME)
    private Date checkTime;

    @ApiParam(value = N_WITHDRAWN_TIME, example = E_WITHDRAWN_TIME)
    private Date withdrawnTime;

    @ApiParam(value = N_PHONE_STATUS, example = E_PHONE_STATUS)
    private Boolean phoneStatus;

    @ApiParam(value = N_PHONE, example = E_PHONE)
    @Length(max = 32)
    private String phone;

    @ApiParam(value = N_EMP_NAME, example = E_EMP_NAME)
    @Length(max = 32)
    private String empName;

    @ApiParam(value = N_WECHAT_STATUS, example = E_WECHAT_STATUS)
    private Boolean wechatStatus;

    @ApiParam(value = N_EMP_NO, example = E_EMP_NO)
    @Length(max = 32)
    private String empNo;

    @ApiParam(value = N_DEP_ID, example = E_DEP_ID)
    @Length(max = 32)
    private String depId;

    @ApiParam(value = N_DEP_NAME, example = E_DEP_NAME)
    @Length(max = 255)
    private String depName;

    @ApiParam(value = N_POSITION_ID, example = E_POSITION_ID)
    @Length(max = 32)
    private String positionId;

    @ApiParam(value = N_POSITION_NAME, example = E_POSITION_NAME)
    @Length(max = 255)
    private String positionName;

    @ApiParam(value = N_SALARY_BASIC, example = E_SALARY_BASIC)
    private BigDecimal salaryBasic;

    @ApiParam(value = N_EMP_SOC, example = E_EMP_SOC)
    private BigDecimal empSoc;

    @ApiParam(value = N_EMP_PF, example = E_EMP_PF)
    private BigDecimal empPf;

    @ApiParam(value = N_EMP_TAX, example = E_EMP_TAX)
    private BigDecimal empTax;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_SORT, example = E_SORT)
    private Integer sort;

    @ApiParam(value = N_RELOAD_COUNT, example = E_RELOAD_COUNT)
    private Boolean reloadCount;

    @ApiParam(value = N_NAME_OR_PHONE, example = E_NAME_OR_PHONE)
    @Length(max = 255)
    private String nameOrPhone;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public SalaryBillQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

